package com.clk.portfoy.complib.piyasa;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.border.EtchedBorder;

import com.clk.desktop.gui.components.basic.ClkButton;
import com.clk.desktop.gui.components.basic.ClkLabel;
import com.clk.desktop.gui.components.basic.ClkPanel;
import com.clk.portfoy.PortfoyStatics;
import com.clk.portfoy.classlib.piyasa.InfPiyasaObserver;
import com.clk.portfoy.classlib.piyasa.Piyasa;
import com.clk.portfoy.complib.ClkDegerLabel;

public class ClkPiyasaPanel extends ClkPanel implements InfPiyasaObserver {

	private class BtnRefreshActionListener implements ActionListener {
		public void actionPerformed(final ActionEvent e) {
			do_btnRefresh_actionPerformed(e);
		}
	}

	private ClkDegerLabel lblBono;
	private ClkLabel bonoClkLabel;
	private ClkDegerLabel lblPetrol;
	private ClkLabel petrolClkLabel;
	private ClkButton btnRefresh;
	private ClkLabel altinClkLabel;
	private ClkLabel euroClkLabel;
	private ClkLabel dolarClkLabel;
	private ClkLabel xutumClkLabel;
	private ClkDegerLabel lblAltinGr;
	private ClkDegerLabel lblEuro;
	private ClkDegerLabel lblDolar;
	private ClkDegerLabel lblXu100;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// ---------------------------------------------------------------------------------
	public ClkPiyasaPanel() {
		super();
		initGUI();
		btnRefresh.setIcon(PortfoyStatics.imgRefresh);
	}

	// ---------------------------------------------------------------------------------
	private void initGUI() {
		setLayout(null);
		setBorder(new EtchedBorder(EtchedBorder.LOWERED));
		{
			lblXu100 = new ClkDegerLabel();
			lblXu100.setBounds(10, 32, 81, 20);
			add(lblXu100);
		}
		{
			lblDolar = new ClkDegerLabel();
			lblDolar.setBounds(97, 32, 81, 20);
			add(lblDolar);
		}
		{
			lblEuro = new ClkDegerLabel();
			lblEuro.setBounds(184, 32, 81, 20);
			add(lblEuro);
		}
		{
			lblAltinGr = new ClkDegerLabel();
			lblAltinGr.setBounds(271, 32, 81, 20);
			add(lblAltinGr);
		}
		{
			xutumClkLabel = new ClkLabel();
			xutumClkLabel.setText("XU100");
			xutumClkLabel.setBounds(10, 6, 81, 20);
			add(xutumClkLabel);
		}
		{
			dolarClkLabel = new ClkLabel();
			dolarClkLabel.setText("DOLAR");
			dolarClkLabel.setBounds(97, 6, 81, 20);
			add(dolarClkLabel);
		}
		{
			euroClkLabel = new ClkLabel();
			euroClkLabel.setText("EURO");
			euroClkLabel.setBounds(184, 6, 81, 20);
			add(euroClkLabel);
		}
		{
			altinClkLabel = new ClkLabel();
			altinClkLabel.setText("ALTIN");
			altinClkLabel.setBounds(271, 6, 81, 20);
			add(altinClkLabel);
		}
		{
			btnRefresh = new ClkButton();
			btnRefresh.addActionListener(new BtnRefreshActionListener());
			btnRefresh.setBounds(535, 6, 53, 46);
			add(btnRefresh);
		}
		{
			petrolClkLabel = new ClkLabel();
			petrolClkLabel.setText("PETROL");
			petrolClkLabel.setBounds(361, 6, 81, 20);
			add(petrolClkLabel);
		}
		{
			lblPetrol = new ClkDegerLabel();
			lblPetrol.setBounds(361, 32, 81, 20);
			add(lblPetrol);
		}
		{
			bonoClkLabel = new ClkLabel();
			bonoClkLabel.setText("BONO");
			bonoClkLabel.setBounds(448, 6, 81, 20);
			add(bonoClkLabel);
		}
		{
			lblBono = new ClkDegerLabel();
			lblBono.setBounds(448, 32, 81, 20);
			add(lblBono);
		}
	}

	// ---------------------------------------------------------------------------------
	protected void do_btnRefresh_actionPerformed(final ActionEvent e) {
		refresh();
	}

	// ---------------------------------------------------------------------------------
	private void refresh() {
		this.lblAltinGr.setText(PortfoyStatics.getDoubleStr(PortfoyStatics.PIYASA.getAltinTL()));
		this.lblBono.setText(PortfoyStatics.getDoubleStr(PortfoyStatics.PIYASA.getBono()));
		this.lblDolar.setText(PortfoyStatics.getDoubleStr(PortfoyStatics.PIYASA.getDolarTL()));
		this.lblEuro.setText(PortfoyStatics.getDoubleStr(PortfoyStatics.PIYASA.getEuroTL()));
		this.lblPetrol.setText(PortfoyStatics.getDoubleStr(PortfoyStatics.PIYASA.getPetrol()));
		this.lblXu100.setText(PortfoyStatics.getDoubleStr(PortfoyStatics.PIYASA.getXu100()));
	}

	// ---------------------------------------------------------------------------------

	@Override
	public void notifyObs(Piyasa p) {
		// TODO Auto-generated method stub
		refresh();
	}
}
